



let axios = require("axios");
let fs = require("fs")

;
(async () => {
    let ret = await axios.get("https://www.dota2.com.cn/datafeed/heroList?task=herolist")
    if(ret.data){
        let heros = {}
        for (let index = 0; index < ret.data.result.heroes.length; index++) {
            let hId = ret.data.result.heroes[index].id
            console.log(ret.data.result.heroes[index].name_loc);
            let hero = await axios.get("https://www.dota2.com.cn/datafeed/hero?hero_id="+hId)
            if(hero.data){
                heros[hId] = hero.data.result
                fs.writeFileSync("./cache/heroData.json", JSON.stringify(heros))
                await sleep(1000 + Math.random()* 1000)
            }
        }

    }
})();





async function sleep(time) {
    return new Promise((a,b) => {
        setTimeout(() => {
            a()
        }, time);
    })
}
